package com.yndsoft.jc.ui.shoppingcart;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yndsoft.jc.R;
import com.yndsoft.jc.model.OrderDet;
import com.yndsoft.jc.ui.shoppingcart.entity.CartBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hasee on 2017/12/3.
 */

public class ConfirmOrderAdapter extends BaseAdapter {

    List<OrderDet> data = new ArrayList<>();
    Context mContext;
    LayoutInflater inflater;

    public ConfirmOrderAdapter(Context mContext) {
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    public void setData(List<OrderDet> data) {
        this.data.clear();
        this.data.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        ShopViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ShopViewHolder();
            convertView = inflater.inflate(R.layout.item_shoppingcart_listview, null);
            viewHolder.product_name = convertView.findViewById(R.id.product_name);
            viewHolder.check_item1 = convertView.findViewById(R.id.check_item1);
            viewHolder.check_item2 = convertView.findViewById(R.id.check_item2);
            viewHolder.check_item3 = convertView.findViewById(R.id.check_item3);
            viewHolder.cart_num = convertView.findViewById(R.id.cart_num);
            viewHolder.limit = convertView.findViewById(R.id.limit);
            viewHolder.check_time = convertView.findViewById(R.id.check_time);
            viewHolder.corner_image = convertView.findViewById(R.id.corner_image);
            viewHolder.item_shoppingcart = convertView.findViewById(R.id.item_shoppingcart);
            viewHolder.item_price = convertView.findViewById(R.id.item_price);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ShopViewHolder) convertView.getTag();
        }

        viewHolder.product_name.setText(data.get(position).getProduct().getSubname());
        viewHolder.check_item1.setText(data.get(position).getProductattribute().getProject());
        viewHolder.check_item2.setText(data.get(position).getProductattribute().getMethod());
        viewHolder.check_item3.setText(data.get(position).getProductattribute().getStandard());
        viewHolder.item_price.setText("￥" + data.get(position).getProductattribute().getPrice());
        viewHolder.cart_num.setText("x" + data.get(position).getNum());
        viewHolder.limit.setText("最低送样量：" + data.get(position).getProductattribute().getLimit() + "g");
        viewHolder.check_time.setText("检测周期：" + data.get(position).getProductattribute().getTime() + "个工作日");

        return convertView;
    }

    class ShopViewHolder {
        TextView product_name, check_item1, check_item2, check_item3, item_price, cart_num, limit, check_time;
        RelativeLayout item_shoppingcart;
        ImageView corner_image;
    }

//    /**
//     * 复选框接口
//     */
//    public interface CheckInterface {
//        /**
//         * 组选框状态改变触发的事件
//         *
//         * @param position  元素位置
//         * @param isChecked 元素选中与否
//         */
//        void checkGroup(int position, boolean isChecked);
//    }

}
